package designPattern;

public class Single {

}


//饿汉式
class Person1{
    //1.类加载就创建对象
    private Person1 person1 = new Person1();

    //2.私有化构造
    private Person1(){

    }

    //3.获取实例
    public Person1 getInstance(){
        return person1;
    }
}


//懒汉式
class Person2{
    //1.类加载就不对象
    private Person2 person2 = null;

    //2.私有化构造
    private Person2(){

    }

    //3.获取实例才创建对象
    public Person2 getInstance(){
        if (person2==null){
            person2 = new Person2();
        }
        return person2;
    }
}


